Sub DisableNextButton
  ButtonNext.Disabled = TRUE
End Sub

Sub ConfigItemChange
	document.all.item(window.event.srcElement.SourceIndex + 1).Disabled = not window.event.SrcElement.checked
End sub

Function AuthorizeMachine
        AuthorizeMachine = FALSE
        oLogging.CreateEntry "About to Call the Web Service and AuthorizeMachine", LogTypeInfo 
        
        ' Create the web service instance
	Set oService = new WebService
	oService.IniFile = "UserGUIWiz.ini"
	oService.SectionName = "AuthorizeMachine"
	
	' Make the web service call
	Set oResult = oService.Query
	If oResult is Nothing then
		oLogging.CreateEntry "Unable to call AuthorizeMachine web service.", LogTypeWarning
                MsgBox(" Authorization Failed")
		Exit Function
        Else 'Success?
                AuthorizeMachine = TRUE
                ButtonNext.Disabled = False
                MsgBox("Successfully Authorized Machine" & vbnewline & vbnewline & "Click Next to Proceed")
                oEnvironment.Item("AUTHORIZED") = "TRUENOW" 
                Exit Function
	End If
End Function

Function AssociateRequestWithMachine
        oLogging.CreateEntry "Entered Function AssociateRequestWithMachine", LogTypeInfo
        Dim iCounter, oResult, oService
	Dim oCONFIGURATION , oConfigurationList
	AssociateRequestWithMachine = FALSE
        If oEnvironment.Item("PRESTAGED") = "TRUENOW" THEN
            oLogging.CreateEntry "We have already Associated this machine. we will not do so again", LogTypeError
            MsgBox("This Machine has already been associated to a configuration" & vbNewLine & "No changes were made to the Database")
            AssociateRequestWithMachine = True
            ButtonNext.Disabled = False
            Exit Function
        End If
       
        ' At least one checkbox must be selected. If not alert the User
        
	Set oConfigurationList = document.getElementsByName("SelectedItem")
	If oConfigurationList is nothing then
                MsgBox("At least one item must be selected")
		Exit Function
	ElseIf oConfigurationList.Length < 1 then
                MsgBox("At least one item must be selected")
		Exit Function 
	End if
        
        iCounter = 0
	For each oCONFIGURATION in oConfigurationList 
            If oCONFIGURATION.Checked Then
                oLogging.CreateEntry "NOW CHECKED = " & iCounter, LogTypeInfo
                oLogging.CreateEntry  "We are using an ID Value of  = " & document.getElementsByName("ConfigID").Item(iCounter).Value, LogTypeInfo
                oLogging.createEntry "Env Var IDENT was " & oEnvironment.Item("IDENT"), LogTypeInfo
                oEnvironment.Item("IDENT") = document.getElementsByName("ConfigID").Item(iCounter).Value
                oLogging.createEntry "And Now Env Var IDENT is " & oEnvironment.Item("IDENT"), LogTypeInfo
                Exit For 
            End if
            iCounter = iCounter + 1
        Next
        
        oLogging.CreateEntry "Env Var PreStaged = " & oEnvironment.Item("Prestaged"), LogTypeInfo
        
        MsgBox("This will take a few minutes" & vbnewline & vbnewline & "Please be patient")  
        
        'Process our Custom Settings file and populate our env variables
        sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTIGather.wsf"" /inifile:UserGUIWiz.ini"
        iRetVal = RunAndLogCUSTOM(sCmd, true)
        
        
        
        oLogging.CreateEntry "About to Call the Web Service and Update the Machine IDENT " & oEnvironment.Item("IDENT"), LogTypeInfo 
        
        ' Create the web service instance
	Set oService = new WebService
	oService.IniFile = "UserGUIWiz.ini"
	oService.SectionName = "UpdateConfigurationWithMACUUID"
	
	' Make the web service call
	Set oResult = oService.Query
	If oResult is Nothing then
		oLogging.CreateEntry "Unable to call UpdateConfigurationWithMACUUID web service.", LogTypeWarning
                oEnvironment.Item("Prestaged") = "ERROR_UPDATING_RECORD"
                oLogging.CreateEntry "Env Var PreStaged = " & oEnvironment.Item("Prestaged"), LogTypeWarning
		Exit Function
        Else 'Success?
                oEnvironment.Item("Prestaged") = "TRUENOW"
                AssociateRequestWithMachine = TRUE
                UpdateConfigButton.Disabled = TRUE
                ButtonNext.Disabled = False
                MsgBox("Successfully Updated Configuration Data" & vbnewline & vbnewline & "Click Next to Proceed")
                Exit Function
	End If

End Function


Function InitializeCONFIGURATIONList
	Dim oConfigurationList
	Dim oTSArray
	Dim oTS
	Dim oSupportedPlatformList
	Dim oPlatform
	Dim bIsSupported
	Dim oTaskId, oTaskList, oTaskOsGuid, oOperatingSystems, oOS, sIsSms, sOSPlatform
	    ' Create the web service instance
	Set oService = new WebService
	oService.IniFile = "UserGUIWiz.ini"
	oService.SectionName = "GetConfigurations"
	' Make the web service call
	Set oConfigurationList = oService.Query
	If oConfigurationList is Nothing then
		oLogging.CreateEntry "Unable to call GetUDDir web service.", LogTypeWarning
		Exit Function
	End If
	CONFIGURATIONS.XMLDocument.LoadXML oConfigurationList.xml
End Function


Function ReadyInitializeCONFIGURATIONList
	' We muck arround with the values, so we need to do some manual cleanup
        oLogging.CreateEntry "Entered Function ReadyInitializeCONFIGURATIONList", LogTypeInfo
	Dim oInput, oConfigurationList
	Dim bFound
	ButtonNext.Disabled = TRUE
	If Not ConfigList.readystate = "complete" then
		Exit function	  
	End If 
	Set oConfigurationList = document.getElementsByName("ConfigID")
	If oConfigurationList is nothing then
                oLogging.CreateEntry "oConfigurationList is nothing. Exiting Function", LogTypeInfo
		Exit function
	End if
        oLogging.CreateEntry "oConfigurationList.Length = " & oConfigurationList.Length, LogTypeInfo
	If oConfigurationList.Length > 0 then
		bFound = FALSE
		For each oInput in oConfigurationList
			If oInput.Value <> "" and StrComp(oInput.Value,ForceAsString(oproperties("ConfigID")),vbTextCompare) = 0 then
				document.all.item(oInput.SourceIndex - 1).click
				ButtonNext.Disabled = FALSE
				bFound = TRUE
			End if
		Next	  
		If not bFound And oConfigurationList.Item(0).Value <> "" then
			' Just select the first item
			document.getElementsByName("SelectedItem").Item(0).click   
			ButtonNext.Disabled = FALSE
		End if
	End if   
	If ForceAsString(oProperties("ConfigID")) <> "" then
		oProperties("ConfigID") = ""
	End if
End function

Function RunAndLogCUSTOM(sCmd, bDebuggable)
	Dim iRetVal
	Dim iShow
	If oLogging.Debug and bDebuggable then
		sCmd = sCmd & " /debug:true"
		iShow = 1
	Else
		iShow = 0
	End if
	oLogging.CreateEntry "About to run command: " & sCmd, LogTypeInfo
	On Error Resume Next
	iRetVal = oShell.Run(sCmd, iShow, true)
	If Err then
		iRetVal = Err.Number
		oLogging.CreateEntry "ERROR executing command " & sCmd & ": " & Err.Description & " (" & Err.Number & ")", LogTypeError
	ElseIf iRetVal = -2147021886 or iRetVal = 0 then
		oLogging.CreateEntry "Successfully executed command " & sCmd & ", rc = " & CStr(iRetVal), LogTypeInfo
	Else
		oLogging.CreateEntry "Non-zero return code executing command " & sCmd & ", rc = " & iRetVal, LogTypeWarning
	End if
	RunAndLogCUSTOM = iRetVal
	On Error Goto 0
End Function